<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("path",request.getContextPath());
%>
 <%@ taglib uri = "http://ckfinder.com" prefix="ckf" %>
 <%@ taglib uri="http://ckeditor.com" prefix="ck" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
	<head>
		<base href="<%=basePath%>">

		<title>添加新闻</title>
		<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
		<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
		<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><!--Jquery版本问题导致上传图片失败 所以换成低版本  -->
		<script type="text/javascript" src="js/jquery.form.js"></script>
		<link type="text/css" rel="stylesheet" href="style/glDatePicker.default.css">
		<script src="js/glDatePicker.js" type="text/javascript"></script>
		<script type="text/javascript" >
		$(document).ready(function(){
			$('#btn_upload').click(function(){
				alert("test");
				 var uploadUrl = "/IntroProject/admin/uploadsFiles.jsp"; //这是我自己的处理文件/图片上传的页面URL
		         var imgUrl = window.showModalDialog(uploadUrl);
		       //在upload结束后通过js代码window.returnValue=...可以将图片url返回给imgUrl变量。
		       //更多window.showModalDialog的使用方法参考

		         //  var urlObj = document.getElementById(theURLElementId);

		         //  urlObj.value = imgUrl;

		          // urlObj.fireEvent("onchange"); //触发url文本框的onchange事件，以便预览图片
		          $('#imageSrc').attr('value',imgUrl);
		          $('#image').attr('src',imgUrl);
		          alert(imgUrl);
			});
			$('#date_str').glDatePicker();
			//$(window).resize(function(){
			//		$('#date_str').glDatePicker();
			//});
			$('#submit_btn').click(function(){
				if($('#date_str').attr('value')=='') {
					alert("请输入日期");
					return;
				}
				
				if($('#image_src').attr('value')=='') {
					alert("请上传图片");
					return;
				}
					
				  document.addNews.submit();
			});
		});
			
	
		function uploadImage(formId) {
			/*
			uploadForm目标表单
			btn_delete删除函数的控件
			show_image显示图片
			message返回消息
			*/
			alert(formId);  
		    $(document).ready(  
		                    function() {  
		                        var options = {  
		                            url : "<%=path%>/material!ajaxGetImage",//跳转到相应的Action  
		                            type : "POST",//提交方式  
		                            dataType : "script",//数据类型  
		                            success : function(msg) {//调用Action后返回过来的数据  
		                                alert(formId+":"+msg);  
		                                if (msg.indexOf("#") > 0) {  
		                                    var data = msg.split("#");  
		                                    //var data = msg.split("#");  
		                                    $("#message"+formId).html("<font color='red'>"+data[0]+data[2]+"</font>");
		                                    //$("#image_src").attr("value",data[1]);
		                                    //$("#image_src2").attr("value",data[1]);
		                                    //$("#showImage").html("<img src='<%=basePath%>"+data[1]+"'/><br/><input type='button' value='删除图片' id='btn_delete'>");
		                                    $("#show_image"+formId).attr("src",data[1]);
		                                    $('#btn_delete'+formId).click(function(){
		                                    	alert("删除："+$("#show_image"+formId).attr("src"));
		                                    	if($("#show_image"+formId).attr("src")==""||$("#show_image"+formId).attr("src")=="abc") {
		                                    		alert("没有图片可删除");
													return ;
				                                }
				                                //alert($("#form3").serializeArray());
		                       					$.get("admin/deleteImg",{ image_src2:$("#show_image"+formId).attr("src")},
		                       						function(data1,statusText) {
		                       						 alert(data1+":"+formId);
		                       						 $("#show_image"+formId).attr("src","abc");
			                       					 $("#message"+formId).html("<font color='red'>"+data1+"</font>");
		                       						},
		                       						"html"
		                       					);
		                       			    });
		                                } else {  
		                                    $("#message"+formId).html(msg);//在相应的位置显示信息  
		                                }  
		                            }  
		                        };  
		                        $("#uploadForm"+formId).ajaxSubmit(options);//绑定页面中form表单的id  
		                        return false;  
		                    }
		    );  
		}  
		
		function test(oEvent){
			   var  e=event || oEvent;

			  //if(e.keyCode>95 && e.keyCode<106)
			  //{
			     
			   //   return true;
			   //}
			return false;

			}
		
		</script>
		<!-- CSS goes in the document HEAD or added to your external stylesheet -->
			<style type="text/css">
				table.gridtable {
					font-family: verdana, arial, sans-serif;
					font-size: 11px;
					color: #333333;
					border-width: 1px;
					border-color: #666666;
					border-collapse: collapse;
				}
				
				table.gridtable th {
					border-width: 1px;
					padding: 8px;
					border-style: solid;
					border-color: #666666;
					background-color: #dedede;
				}
				
				table.gridtable td {
					border-width: 1px;
					padding: 8px;
					border-style: solid;
					border-color: #666666;
					background-color: #ffffff;
				}
		</style>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	</head>

	<body>
		添加新闻
		<!-- 
		<br />
		图片预览 <div id="showImage"></div> 
		<form id="form2" method="post" enctype="multipart/form-data"> 
 			<input id="fileupload" name="fileMaterial" type="file" /> 
 			<div id="message"></div>   
 			<input type="button" class="right-button02" onclick="uploadImage()"  value="上传" /> 
		</form> 
		 -->
		  
		<table class="gridtable">
			<tr>
			    <th>图预览</th>
			    <th>图片</th>
			    <th>上传</th>
			    <th>删除</th>
			    <th>消息</th>
			    
			</tr>
			
			
			<tr>
				<td><img width="250px" height="250px" src="" alt="请上传图片" name="show_image1" id="show_image1"/></td>
				<form id="uploadForm1" method="post" enctype="multipart/form-data"> 
		    		<td><input id="fileupload1" name="fileMaterial" type="file" /></td>
		    		<td><input type="button" class="right-button02" onclick="uploadImage(1)"  value="上传" id="submit1"/> </td>
		    		<td><input type='button' value='删除图片' id='btn_delete1'/></td>
		    		<td><div id="message1"></div></td>   
		    	</form> 
		    </tr>
		    <tr>
				<td><img width="250px" height="250px" src="" alt="请上传图片" name="show_image2" id="show_image2"/></td>
				<form id="uploadForm2" method="post" enctype="multipart/form-data"> 
		    		<td><input id="fileupload2" name="fileMaterial" type="file" /></td>
		    		<td><input type="button" class="right-button02" onclick="uploadImage(2)"  value="上传" id="submit1"/> </td>
		    		<td><input type='button' value='删除图片' id='btn_delete2'/></td>
		    		<td><div id="message2"></div> </td> 
		    	</form> 
		    </tr>
		    <tr>
				<td><img width="250px" height="250px" src="" alt="请上传图片" name="show_image3" id="show_image3"/></td>
				<form id="uploadForm3" method="post" enctype="multipart/form-data"> 
		    		<td><input id="fileupload3" name="fileMaterial" type="file" /></td>
		    		<td><input type="button" class="right-button02" onclick="uploadImage(3)"  value="上传" id="submit3"/> </td>
		    		<td><input type='button' value='删除图片' id='btn_delete3'/></td>
		    		<td><div id="message3"></div></td>   
		    	</form> 
		    </tr>
		</table>
		
		<s:form action="addNewsAction" id='addNews'>
			 标题:<input type="text" size="60" name="title"/><br/>
			 日期:<input type="text" id="date_str" name="date_str"  onkeydown="return test(event);" /><br/>
			 <input type="hidden" name="image_src" value="" id="image_src"/>
			 <input type="hidden" name="type" value="1" id="type"/>
			 <s:textarea id="txt" name="content" rows="5" cols="120"></s:textarea>			 
			 <ckf:setupCKEditor  basePath="/IntroProject/ckfinder/"  editor="txt"/>
			<ck:replace replace="txt" basePath="/IntroProject/ckeditor/"></ck:replace>
			<br/>	
			<%--
					<textarea rows="30" cols="50" name="editor01">请输入.</textarea>
					<script type="text/javascript">
						var editor = CKEDITOR.replace('editor01');
					</script>
			--%><br/>
		</s:form>
		 <input type="button" value="提交" id='submit_btn'/>   		
	</body>
</html>
